/**********************************************************************************************************************
 *
 * Project:    mGameEngine
 * File:       terrain.h
 * Author:     karooolek
 * Created on: Jun 23, 2009
 *
 **********************************************************************************************************************/

#ifndef TERRAIN_H_
#define TERRAIN_H_

#include "scenenode.h"
#include "terraintile.h"

namespace mGameEngine
{
namespace Game
{

/**
 * Static terrain.
 * TODO
 */
class Terrain : public SceneNode
{
protected:
    /**
     * Height field.
     */
    Heightfield _heightField;

    /**
     * Surface texture.
     */
    const Graphics::Texture *_texture;

    /**
     * Tile size.
     */
    float _tileSize;

    /**
     * Maximal terrain resolution.
     */
    float _resolution;

    /**
     * Generate tiles.
     */
    virtual void _generateTiles();

public:
    /**
     * Create flat terrain.
     */
    Terrain();

    /**
     * Create terrain with specified height map and size.
     * Terrain tiles size can be specified.
     * Tiles will be automatically generated.
     * @param heightMap height map.
     * @param texture surface texture.
     * @param size size.
     * @param tileSize single tile size.
     * @param resolution maximal terrain resolution.
     */
    Terrain(const Graphics::Image *heightMap,
            const Graphics::Texture *texture,
            const Vector3 &size,
            float tileSize = 100.0f,
            float resolution = 2.5f);

    /**
     * Destroy terrain.
     */
    virtual ~Terrain();

    /**
     * Set terrain height map.
     * If height map changes, tiles will be automatically regenerated.
     * @param heightMap height map.
     */
    virtual void setHeightMap(const Graphics::Image *heightMap);

    /**
     * Get terrain height field.
     * @return terrain height field.
     */
    const Heightfield *getHeightField() const
    {
        return &_heightField;
    }

    /**
     * Set terrain surface texture.
     * @param texture surface texture.
     */
    void setTexture(const Graphics::Texture *texture)
    {
        _texture = texture;
    }

    /**
     * Get terrain surface texture.
     * @return terrain surface texture.
     */
    const Graphics::Texture *getTexture() const
    {
        return _texture;
    }

    /**
     * Set terrain tiles size.
     * Tiles will be automatically regenrated.
     * @param tileSize single tile size.
     */
    virtual void setTileSize(float tileSize);

    /**
     * Get terrain tiles size.
     * @return single tile size.
     */
    float getTileSize() const
    {
        return _tileSize;
    }

    /**
     * Set terrain maximal resolution.
     * @param resolution maximal resolution.
     */
    void setResolution(float resolution)
    {
        _resolution = resolution;
    }

    /**
     * Get terrain maximal resolution.
     * @return terrain maximal resolution.
     */
    float getResolution() const
    {
        return _resolution;
    }
};

}
}

#endif // TERRAIN_H_
